<?php

// Namespace

namespace Loop;


/**
 * @package		Loop
 * @category	Model
 */

class CProfilingEvent extends \Loop\CObject
{
	/**
	 *
	 */
	
	protected function createProperties()
	{
		$this->createProperty
		(
			'input',
			array
			(
				'type' => TYPE_TEXT
			)
		);

		$this->createProperty
		(
			'lineOfClosure',
			array
			(
				'type' => TYPE_INTEGER_UNSIGNED
			)
		);

		$this->createProperty
		(
			'lineOfStart',
			array
			(
				'type' => TYPE_INTEGER_UNSIGNED
			)
		);

		$this->createProperty
		(
			'maxMemory',
			array
			(
				'type' => TYPE_REAL_UNSIGNED
			)
		);

		$this->createProperty
		(
			'message',
			array
			(
				'type' => TYPE_STRING_LONG
			)
		);

		$this->createProperty
		(
			'output',
			array
			(
				'type' => TYPE_TEXT
			)
		);

		$this->createProperty
		(
			'pathToFileOfClosure',
			array
			(
				'type' => TYPE_STRING_LONG
			)
		);

		$this->createProperty
		(
			'pathToFileOfStart',
			array
			(
				'type' => TYPE_STRING_LONG
			)
		);

		$this->createProperty
		(
			'profilingThreadId',
			array
			(
				'className' => 'CProfilingThread',
				'isAssociation' => true,
				'extensionId' => EXTENSION_LOOP
			)
		);

		$this->createProperty
		(
			'step',
			array
			(
				'type' => TYPE_STRING_SHORT
			)
		);		

		$this->createProperty
		(
			'timeOfClosure',
			array
			(
				'type' => TYPE_REAL_UNSIGNED
			)
		);

		$this->createProperty
		(
			'timeOfStart',
			array
			(
				'type' => TYPE_REAL_UNSIGNED
			)
		);

		$this->createProperty
		(
			'type',
			array
			(
				'type' => TYPE_STRING_SHORT
			)
		);
	}


	/**
	 *
	 */

	public function getDuration()
	{
		return max(0, $this->getTimeOfClosure() - $this->getTimeOfStart());
	}
}

?>
